package dao.impl;

import dao.Review_recordDao;
import entry.Review_record;
import entry.Ticket_open;
import util.DBHelper;

import java.util.ArrayList;
@SuppressWarnings("all")
public class Review_recordDaoImpl implements Review_recordDao {


    private DBHelper db=new DBHelper();

    /**
     * 向审核记录表中增加审核信息
     * @param rd 审核记录实体类对象
     * 添加成功返回真（需要if判断）
     */
    @Override
    public boolean insertReview_record(Review_record rd) {
        String sql="insert into review_record values(null,?,?,current_date(),?,?)";
        int i=db.updateTable(sql,rd.getTicket_open_id(),rd.getCreator_id(),rd.getReview_status(),rd.getRemark());
        return i==0?false:true;
    }

    /**
     * 更改审核记录表中的信息
     * @param rd
     * @return
     *
     */
    @Override
    public boolean updateReview_record(Review_record rd) {
        String sql="update review_record set review_status=?, remark=? where ticket_open_id=?";
        int i=db.updateTable(sql,rd.getReview_status(),rd.getRemark(),rd.getTicket_open_id());
        return i==0?false:true;
    }

    @Override
    public ArrayList<Ticket_open> queryDetails(String no) {
        String sql = "select * from ticket_open join enterprise on ticket_open.enterprise_id = enterprise.id JOIN instituty " +
                "ON ticket_open.instituty_id = instituty.instituty_id where status = '开单中' and no=?";

        return db.query(sql,Ticket_open.class,no);
    }

    @Override
    public ArrayList<Ticket_open> queryByStatues() {
        String sql = "select * from ticket_open join enterprise on ticket_open.enterprise_id = enterprise.id JOIN instituty " +
                "ON ticket_open.instituty_id = instituty.instituty_id where status = '开单中' ";
        return db.query(sql,Ticket_open.class);
    }
}
